home *** CD-ROM | disk | FTP | other *** search
- #include "BltMacros.h"
-
- // --------------------------------------------------------------------------------------
-
- //
- // Code that draws our actual effect. Note that this code is very slow.
- // It is intended only as an example/placeholder for code you will write.
- // A good first optimization would be to replace the floating-point math
- // with fixed point.
- //
- // 32 bit case. For explanation of what this function does, see the
- // comments in the 16 bit case, above.
- //
- short isPressed(unsigned short k );
- const short key_option = 0x3a;
- const short key_shift = 0x38;
-
- static void EffectFilter32(BlitGlobals *glob);
- static void EffectFilter32(BlitGlobals *glob)
- {
- if (isPressed (key_option)) {
- long height = glob->height;
- long *srcA = glob->sources[0].srcBaseAddr;
- //vector unsigned char srcA = *(vector unsigned char*)glob->sources[0].srcBaseAddr;
- long *dst = glob->dstBaseAddr;
- long srcABump = glob->sources[0].srcRowBytes - (glob->width * 4);
- long dstRowBytes = glob->dstRowBytes;
- long* dstBaseAddr = glob->dstBaseAddr;
- long srcRowBytes = glob->sources[0].srcRowBytes;
- long* srcBaseAddr = glob->sources[0].srcBaseAddr;
- UInt8* puiRandoms = glob->puiRandoms;
- UInt8* puiEndRandoms = puiRandoms + 32768;
- UInt8* puiBrightnessRoll = glob->puiBrightnessRoll;
- UInt8* puiEndBrightness = glob->puiBREnd;
-
- puiRandoms += ((Random () * 16000) / 65535) + 16000;
-
- while (height--)
- {
- vector unsigned char lowPart, hiPart, Align;
- vector unsigned char srcAVec;
- vector unsigned char randomVec;
- vector unsigned char dstVec;
- vector unsigned char brightnessVec;
-
- long width = glob->width;
-
- srcA = (void *) (((Ptr) srcBaseAddr) + (srcRowBytes * (glob->height - height - 1)));
- srcA += (*puiRandoms/4);
- dst = (void*)(((Ptr)dstBaseAddr) + ((glob->height - height - 1) * dstRowBytes));
- width -= (long)(*puiRandoms/4);
- //dst += (long)(*puiRandoms/4);
-
- brightnessVec = vec_ld (0, puiBrightnessRoll);
- brightnessVec = vec_splat (brightnessVec, 0);
-
- //brightnessVec = *(vector unsigned char*)puiBrightnessRoll;
- puiBrightnessRoll++;
- if (puiBrightnessRoll > puiEndBrightness) {
- puiBrightnessRoll = glob->puiBRStart;
- }
-
- // Account for wide vectors
- width /= 4;
-
- while (width--)
- {
- // Get the source into a vector
- lowPart = vec_ld (0, (UInt8*)srcA);
- hiPart = vec_ld (16, (UInt8*)srcA);
- Align = vec_lvsl (0, (UInt8*)srcA);
- srcAVec = vec_perm (lowPart, hiPart, Align);
- srcA += 4;
-
- // Get the random bits into a vector and add them to the source
- randomVec = vec_ld (0, (UInt8*)puiRandoms);
- dstVec = vec_adds (srcAVec, randomVec);
- //dstVec = srcAVec;
- puiRandoms+=16;
- if (puiRandoms > puiEndRandoms) {
- puiRandoms = glob->puiRandoms;
- }
-
- // Add in the brightness
- dstVec = vec_adds (dstVec, brightnessVec);
- vec_st (dstVec, 0, (UInt8*)dst);
- dst += 4;
- }
- }
- } else {
- long height = glob->height;
- long *srcA = glob->sources[0].srcBaseAddr;
- long *dst = glob->dstBaseAddr;
- long srcABump = glob->sources[0].srcRowBytes - (glob->width * 4);
- long dstRowBytes = glob->dstRowBytes;
- long* dstBaseAddr = glob->dstBaseAddr;
- long srcRowBytes = glob->sources[0].srcRowBytes;
- long* srcBaseAddr = glob->sources[0].srcBaseAddr;
- UInt8* puiRandoms = glob->puiRandoms;
- UInt8* puiEndRandoms = puiRandoms + 32768;
- UInt8* puiBrightnessRoll = glob->puiBrightnessRoll;
- UInt8* puiEndBrightness = glob->puiBREnd;
-
- puiRandoms += ((Random () * 16000) / 65535) + 16000;
-
- while (height--)
- {
- long width = glob->width;
-
- srcA = (void *) (((Ptr) srcBaseAddr) + (srcRowBytes * (glob->height - height - 1)));
- dst = (void*)(((Ptr)dstBaseAddr) + ((glob->height - height - 1) * dstRowBytes));
- width -= (long)(*puiRandoms/4);
- dst += (long)(*puiRandoms/4);
- puiRandoms++;
- if (puiRandoms > puiEndRandoms) {
- puiRandoms = glob->puiRandoms;
- }
-
- puiBrightnessRoll++;
- if (puiBrightnessRoll > puiEndBrightness) {
- puiBrightnessRoll = glob->puiBRStart;
- }
-
- while (width--)
- {
- UInt32 thePixelValue;
- UInt16 pixels[4];
- UInt16 uiRandom;
-
- thePixelValue = Get32(srcA);
- srcA++;
-
- puiRandoms++;
- if (puiRandoms > puiEndRandoms) {
- puiRandoms = glob->puiRandoms;
- }
- uiRandom = (UInt16)*puiRandoms;
-
- pixels[0] = thePixelValue >> 24;
- pixels[1] = ((thePixelValue >> 16) & 0xff) + (UInt16)uiRandom;
- pixels[2] = ((thePixelValue >> 8) & 0xff) + (UInt16)uiRandom;
- pixels[3] = ((thePixelValue >> 0) & 0xff) + (UInt16)uiRandom;
-
- pixels [ 1 ] = (float)pixels [ 1 ] + *puiBrightnessRoll;
- pixels [ 2 ] = (float)pixels [ 2 ] + *puiBrightnessRoll;
- pixels [ 3 ] = (float)pixels [ 3 ] + *puiBrightnessRoll;
-
- if (pixels [ 1 ] > 255) {
- pixels [ 1 ] = 255;
- }
-
- if (pixels [ 2 ] > 255) {
- pixels [ 2 ] = 255;
- }
-
- if (pixels [ 3 ] > 255) {
- pixels [ 3 ] = 255;
- }
-
- thePixelValue = (pixels[0] << 24) | (pixels[1] << 16) | (pixels[2] << 8) | (pixels[3]);
-
- Set32(dst,thePixelValue);
- dst++;
-
- }
- }
- }
-
- } // DrawEffectFrameEffect32Bit
-
- short isPressed(unsigned short k )
- // k = any keyboard scan code, 0-127
- {
- unsigned char km[16];
-
- GetKeys( (unsigned long *) km);
- return ( ( km[k>>3] >> (k & 7) ) & 1);
- }
-